<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

/**
*
* @package MediaLibrary
* @copyright 2009 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru);Rob de Cleen(rob@decleen.com)
* Homepage: http://www.joomlawebserver.com
* @version: 1.5.3 Basic $
*
**/




class mosMediaLibrary_review extends mosDBTable {
	/** @var int Primary key */
	var $id = null;
	/** @var int - the book id this lend is assosiated with*/
	var $fk_mediaid=null;	
	/** @var int - the user id of the user who lent this book; can also be null if $user_name is set*/
	var $fk_userid=null;
	/** @var datetime - date when adding this review*/
	var $date=null;
	/** @var comment - the comment to this */
	var $comment=null;
	/** @var titel */
	var $title= null;
	/** @var rating */
	var $rating= 0;
	/** @var boolean */
	var $checked_out=null;
	/** @var time */
	var $checked_out_time=null;
	
	/**
	* @param database - A database connector object
	*/
	function mosMediaLibrary_review( &$db ) {
		$this->mosDBTable( '#__medialibrary_review', 'id', $db );
	}
	
	/**
	 * @return array - name: the string of the user the book is lent to - e-mail: the e-mail address of the user
	 */
	function getReviewFrom(){
		$retVal['name'] = null;
		$retVal['email'] = null;
		if($this->fk_userid != null && $this->fk_userid != 0){
			$this->_db->setQuery( "SELECT name, email from #__users where id=$this->fk_userid");
			$help = $this->_db->loadRow();
			$retVal['name'] = $help[0];
			$retVal['email'] = $help[1];
		}
		else{
			$retVal['name'] = _MEDIALIBRARY_LABEL_ANONYMOUS;
			$retVal['email'] = null;
		}
		return $retVal;
	}
	
	function toXML(& $xmlDoc){
		
		//create and append name element 
		$retVal = & $xmlDoc->createElement("review"); 
		
		$fk_userid = & $xmlDoc->createElement("fk_userid");
		$fk_userid->appendChild($xmlDoc->createTextNode($this->fk_userid));
		$retVal->appendChild( $fk_userid);
		
		$rating = & $xmlDoc->createElement("rating");
		$rating->appendChild($xmlDoc->createTextNode($this->rating));
		$retVal->appendChild( $rating );

		$date = & $xmlDoc->createElement("date");
		$date->appendChild($xmlDoc->createTextNode($this->date));
		$retVal->appendChild( $date );

		$title = & $xmlDoc->createElement("title");
		$title->appendChild($xmlDoc->createCDATASection($this->title));
		$retVal->appendChild( $title);

		$comment = & $xmlDoc->createElement("comment");
		$comment->appendChild($xmlDoc->createCDATASection($this->comment));
		$retVal->appendChild( $comment);		
		
		return $retVal;
	}
}
?>

